package leetcode.primary;

import java.util.Arrays;

public class T88 {
    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int[] temp = new int[m+n];
        int i=0,j=0,k=0;
        while (i<m && j<n){
            if (nums1[i]<=nums2[j]){
                temp[k++]=nums1[i++];
            }else {
                temp[k++] = nums2[j++];
            }
        }
        if (i==m){
            while (j<n){
                temp[k++] = nums2[j++];
            }
        }
        if (j==n){
            while (i<m){
                temp[k++] = nums1[i++];
            }
        }

        for (int l = 0; l < m + n; l++) {
            nums1[l] = temp[l];
        }
    }

    public static void main(String[] args) {
        T88 test = new T88();
        int[] nums1 = new int[]{1};
        int[] nums2 = new int[]{};
        test.merge(nums1, 1, nums2, 0);
        for (int i : nums1) {
            System.out.print(i+" ");
        }
    }
}
